/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.pw.elka.gtsna.centrality.betweenness;

import java.util.HashSet;
import java.util.Set;

import edu.pw.elka.gtsna.centrality.GroupNodeCentrality;
import edu.pw.elka.gtsna.graph.Graph;

/**
 *
 * @author szczepan
 */
public class GroupNodeBetweenness extends GroupNodeCentrality {
    
    
    public GroupNodeBetweenness(Graph graph) {
    	super(graph);        
    }
    
    NodeBetweennessCentrality betCen = new NodeBetweennessCentrality(graph){
      @Override
      void accumulation(int source) {
          if (group.contains(source)) {
              stack.clear();
              return;
          }
          while (!stack.isEmpty()){
          	Integer w = stack.pop();
              for(Integer v: pred.get(w)){
                  double i = 0.0;
                  if (!group.contains(w)) {
                      i=delta.get(w);
                  } else {
                      continue;
                  }                 
                  delta.put(v, delta.get(v) + ((sigma.get(v).doubleValue()*(1.0 + i))/sigma.get(w).doubleValue()));
              }
              if (!w.equals(source) && group.contains(w)) {
                  centrality += (delta.get(w)/2.0);
              }
          }
      }    	
    };
    

	@Override
	public double computeCentrality(Set<Integer> group) {
		centrality=0;
		this.group.clear();
		this.group.addAll(group);
		
		betCen.computeCentrality();
		return 	centrality;
	}


    
}
